package com.otaku.producer.rabbitMq;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import com.alibaba.fastjson.JSONObject;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class FanoutProducer {

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void send(String queueName) {
        /**
         * 定义消息头部
         */
        JSONObject object = new JSONObject();
        object.put("email","honggezz@163.com");
        object.put("sms","1234qwer");
        //给数据绑定唯一标识
        Message message = MessageBuilder.withBody(object.toJSONString().getBytes())
                .setContentType(MessageProperties.CONTENT_TYPE_JSON)
                .setContentEncoding("UTF-8").setMessageId(UUID.randomUUID().toString()).build();
        amqpTemplate.convertAndSend(queueName, message);
    }
}
